package ch.elexis.easy.developer.resources.ui;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;

import ch.elexis.core.Session;
import ch.elexis.core.admin.InsufficientRightsException;
import ch.elexis.core.data.IPersistentObject;
import ch.elexis.core.data.Query;
import ch.elexis.easy.developer.resources.model.SampleData;
import ch.elexis.easy.ui.boilerplates.TableContentProvider;
import ch.elexis.easy.ui.boilerplates.TableLabelProvider;

public class Sub1 extends Composite {
	public Sub1(Composite parent){
		super(parent,SWT.NONE);
		setLayout(new GridLayout());
		final TableViewer tv=new TableViewer(this);
		GridDataFactory.fillDefaults().applyTo(tv.getControl());
		tv.setContentProvider(new TableContentProvider(){

			@Override
			public Object[] getElements(Object inputElement){
				Query qbe=new Query(SampleData.class);
				IPersistentObject[] ret=Session.getInstance().getPersistentObjectManager().executeQuery(qbe);
				return ret;
			}
			
		});
		tv.setLabelProvider(new TableLabelProvider(){

			@Override
			public String getColumnText(Object element, int columnIndex){
				try {
					return ((SampleData)element).getLabel();
				} catch (InsufficientRightsException e) {
					return "insufficient rights";
				}
			}
		
			
		});
		tv.setInput(this);
	}
}
